Skip to content

fix(core): stop unique_name_from_base reseeding the global random module - #6600

Open
nursnaaz wants to merge 1 commit into
aws:masterfrom
nursnaaz:fix/unique-name-global-random-seed
Open

nursnaaz wants to merge 1 commit into
aws:masterfrom
nursnaaz:fix/unique-name-global-random-seed

Conversation

@nursnaaz

Copy link
Copy Markdown

Summary

unique_name_from_base and unique_name_from_base_uuid4 in sagemaker-core call random.seed(int(uuid.uuid4())). That reseeds the global random module of the caller's process. A user who sets random.seed(42) for reproducible code and then creates a job, model or endpoint name gets different random numbers afterwards. The seed call in unique_name_from_base_uuid4 does nothing useful, because that function never draws from random.

Changes

  • unique_name_from_base_uuid4: removed the random.seed(...) call.
  • unique_name_from_base: the 4-digit hex suffix now comes from random.SystemRandom().randrange(16**4). This draws from the OS entropy source, so names stay unpredictable (the goal of #using uuid to randomize, otherwise system timestamp is used #3046) and the global state is untouched.

Tests

Two new tests in sagemaker-core/tests/unit/test_common_utils.py set random.seed(1234), create a name, and check that the next random number is unchanged. Both fail on master and pass with this change. All 300 tests in that file pass. black and flake8 are clean. pylint shows only warnings that were already there. I did not run the full tox suite.

Generated by AI tools, and reviewed by Mohamed Noordeen Alaudeen (@nursnaaz).

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

This branch is waiting to be deployed

1 waiting deployment
manual-approval — eb06f8b5 Waiting Nov 21, 2026 by nursnaaz via wait-for-approval #911
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant